package com.eqdd.yiqidian.ui;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.view.View;

import com.eqdd.inputs.AndroidNextInputs;
import com.eqdd.inputs.WidgetAccess;
import com.eqdd.nextinputs.StaticScheme;
import com.eqdd.yiqidian.EmailCheckActivityCustom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.bean.BaseBean;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpPresneter;
import com.eqdd.yiqidian.utils.GsonUtils;
import com.eqdd.yiqidian.utils.ToastUtil;

public class EmailCheckActivity extends BaseActivity {
    private EmailCheckActivityCustom dataBinding;
    private AndroidNextInputs inputs;
    private WidgetAccess access;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_email_check);
        initTopTitleBar(View.VISIBLE, "邮箱找回密码");
    }

    @Override
    public void initData() {
        inputs = new AndroidNextInputs();
        access = new WidgetAccess(this);
        inputs  // 必选，手机号
                .add(access.findEditText(R.id.et_phone))
                .with(StaticScheme.Required(), StaticScheme.ChineseMobile())
                // 必选 ，密码8~18
                .add(access.findEditText(R.id.et_email))
                .with(StaticScheme.Required(), StaticScheme.Email());
    }

    @Override
    public void setView() {

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.btn_submit:
                if (inputs.test()){
                    new HttpPresneter.Builder<String>(HttpConfig.USER_EMAIL_CHECK,String.class,this)
                            .Params("temail",dataBinding.etEmail.getText().toString())
                            .Params("aname",dataBinding.etPhone.getText().toString())
                            .setOnHttpListener(new HttpPresneter.OnHttpListener<String>() {
                                @Override
                                public void onError(Throwable e) {

                                }

                                @Override
                                public void onNext(String s) {

                                    BaseBean baseBean = GsonUtils.changeGsonToBean(s, BaseBean.class);
                                    ToastUtil.showShort(baseBean.getMsg());
                                    if (baseBean.getStatus()==200){
                                        Bundle bundle = new Bundle();
                                        bundle.putString("phone",dataBinding.etPhone.getText().toString().trim());
                                        startActivity(EmailPasswordGetActivity.class,bundle);
                                        finish();
                                    }

                                }
                            })
                            .build()
                            .post();
                }
        }
    }
}
